package com.shujia.spark.mllib

import org.apache.spark.ml.classification.LogisticRegressionModel
import org.apache.spark.ml.linalg
import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.sql.SparkSession

object Demo3UseModel {
  def main(args: Array[String]): Unit = {

    val spark: SparkSession = SparkSession
      .builder()
      .appName("source")
      .master("local")
      .config("spark.sql.shuffle.partitions", "1")
      .getOrCreate()


    /**
      * 使用模型
      *
      */

    //1、加载模型
    val model: LogisticRegressionModel = LogisticRegressionModel.load("data/model")


    /**
      * 构建一个病人
      * 0 1:4.2 2:3.4 3:2.5 4:97.3 5:67.7 6:58.3 7:87
      * 1 1:6.2 2:5.0 3:3.4 4:153.3 5:92.2 6:95.4 7:53
      *
      */

    //    val vector: linalg.Vector = Vectors.dense(4.2, 3.4, 2.5, 97.3, 67.7, 58.3, 87)
    val vector: linalg.Vector = Vectors.dense(6.2, 5.0, 3.4, 153.3, 92.2, 95.4, 53)

    //预测数据
    val y: Double = model.predict(vector)

    println(y)

  }
}
